package edu.zqu.collegeField.project.controller;


import cn.hutool.core.util.StrUtil;
import edu.zqu.collegeField.project.po.FieldStatus;
import edu.zqu.collegeField.project.service.FieldStatusService;
import edu.zqu.collegeField.project.vo.FieldStatusVo;
import edu.zqu.common.result.ZQUResult;
import edu.zqu.common.status.HttpStatus;
import edu.zqu.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * <p>
 * 场地状态 前端控制器
 * </p>
 *
 * @author 廖森
 * @since 2020-06-28
 */
@RestController
@RequestMapping("/api")
@Api(tags = "场地状态")
public class FieldStatusController {
    @Autowired
    private FieldStatusService fieldStatusService;

    @ApiOperation(value = "获取场地状态列表")
    @GetMapping(value = "/fieldStatuses")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collegeId", value = "学校id", paramType = "query", required = true),
            @ApiImplicitParam(name = "schoolId", value = "校区id", paramType = "query", required = false),
            @ApiImplicitParam(name = "areaId", value = "功能区id", paramType = "query", required = false),
            @ApiImplicitParam(name = "fieldId", value = "场地id", paramType = "query", required = false),
            @ApiImplicitParam(name = "fieldTypeId", value = "场地类型id", paramType = "query", required = false),
            @ApiImplicitParam(name = "calendarDate", value = "日期", paramType = "query", required = false),
            @ApiImplicitParam(name = "timeTableId", value = "作息id", paramType = "query", required = false),
            @ApiImplicitParam(name = "status", value = "状态/空闲状态不记录1上课 2开会 3外借", paramType = "query", required = false)
    })
    public ZQUResult get(BigInteger collegeId,
                         BigInteger schoolId,
                         BigInteger areaId,
                         BigInteger fieldId,
                         BigInteger fieldTypeId,
                         BigInteger calendarId,
                         BigInteger timeTableId,
                         Integer status
    ) {
        List<FieldStatusVo> fieldStatusVoList = fieldStatusService.get(collegeId, schoolId, areaId, fieldId, fieldTypeId,
                calendarId, timeTableId, status);
        if (StringUtils.isNotEmpty(fieldStatusVoList)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldStatusVoList);
        } else return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败", null);
    }

    @ApiOperation(value = "获取场地状态信息", response = FieldStatusVo.class)
    @GetMapping(value = "/fieldStatus/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地状态id", paramType = "path", required = true)
    })
    public ZQUResult getById(@PathVariable BigInteger id) {
        FieldStatusVo fieldStatusVo = fieldStatusService.getById(id);
        if (StringUtils.isNotNull(fieldStatusVo)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldStatusVo);
        }
        return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败", null);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/fieldStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldStatus", name = "FieldStatus", value = "场地状态对象", paramType = "query", required = true)
    })
    public ZQUResult add(@RequestBody FieldStatus fieldStatus) {
        int rs = fieldStatusService.add(fieldStatus);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "添加成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "添加失败", null);
    }

    @ApiOperation(value = "更新")
    @PutMapping(value = "/fieldStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldStatus", name = "FieldStatus", value = "场地状态对象", paramType = "query", required = true)
    })
    public ZQUResult update(@RequestBody FieldStatus fieldStatus, String calendarDate) {
        int rs = fieldStatusService.update(fieldStatus);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "修改成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "修改失败", null);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/fieldStatus/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地状态id", paramType = "path", required = true),
            @ApiImplicitParam(name = "byWho", value = "用户id", paramType = "query", required = true)
    })
    public ZQUResult delete(@PathVariable BigInteger id, BigInteger byWho) {
        int rs = fieldStatusService.delete(id, byWho);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "删除成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "删除失败", null);
    }
}

